<template>
  <el-dialog
    title="分包合同完成列表"
    :visible.sync="show"
    width="900px"
    center
    append-to-body
  >
    <div class="content-box">
      <com-table
        v-model="selectNode"
        highlight-current-row
        :data="dataList"
        :columns="columns"
        @pageChange="pageChange"
      >
        <template v-slot:createTime="{row: {createTime}}">
          {{ dateFormat(createTime) }}
        </template>
        <template v-slot:signTime="{row: {signTime}}">
          {{ dateFormat(signTime) }}
        </template>
        <template v-slot:elecContractUpload="{row: {elecContractUpload}}">
          {{ elecContractUpload?'是':'否' }}
        </template>
        <template v-slot:paperContractUpload="{row: {paperContractUpload}}">
          {{ paperContractUpload?'是':'否' }}
        </template>
        <template v-slot:status="{row: {status}}">
          {{ statusMap(status) }}
        </template>
        <template v-slot:options="{row}">
          <el-button type="success" size="mini" @click="getCheckList(row)">引入</el-button>
        </template>
      </com-table>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" :loading="searching" @click="confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getLaborContractFinishInfoList } from '@/api/runManage'
import moment from 'moment'
import { getDictName } from '@/utils/comm'
import { projectInfoProjStatus, projectInfoProjType, projectInfoProjMode } from '@/utils/dicData'
export default {
  name: 'ProjectList',
  components: {

  },
  props: {
    showModal: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      projectInfoProjStatus,
      projectInfoProjType,
      projectInfoProjMode,
      getDictName,
      visible: false,
      name: '',
      total: 0,
      pageParams: {
        pageNum: 1,
        pageSize: 10
      },
      selectNode: null,
      searching: false,
      dataList: [], // 列表
      columns: [
        {
          label: '分包队伍编号',
          prop: 'teamNumber'
        },
        {
          label: '分包队伍名称',
          prop: 'teamName'
        },
        {
          label: '分包合同编号',
          prop: 'contractNumber'
        },
        {
          label: '分包合同名称',
          prop: 'contractName'
        },
        // {
        //   label: '部门名称',
        //   prop: 'departmentName'
        // },
        {
          label: '初始合同金额(元)',
          prop: 'initAmount'
        },
        {
          label: '签订时间',
          prop: 'signTime',
          slot: 'signTime'
        },
        {
          label: '描述',
          prop: 'description'
        },
        {
          label: '备注',
          prop: 'remark'
        },
        {
          label: '电子版合同是否上传',
          prop: 'elecContractUpload',
          slot: 'elecContractUpload'
        },
        {
          label: '纸质版合同是否上传',
          prop: 'paperContractUpload',
          slot: 'paperContractUpload'
        },
        // {
        //   label: '新增流程id',
        //   prop: 'addWorkflowId'
        // },
        {
          label: '流程状态',
          prop: 'status',
          slot: 'status'
        },
        {
          label: '创建人名称',
          prop: 'founderName'
        },
        {
          label: '创建人单位',
          prop: 'founderOrganizationName'
        },
        {
          label: '创建时间',
          prop: 'createTime',
          slot: 'createTime'
        }
      ]
    }
  },
  computed: {
    show: {
      get() {
        return this.showModal
      },
      set(val) {
        this.$emit('update:showModal', val)
      }
    }
  },
  watch: {
    showModal: {
      handler(newData) {
        if (newData) {
          this.getDataList()
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {

  },
  methods: {
    statusMap(status) {
      const sMap = {
        1: '编制中',
        2: '审批中',
        3: '审批通过',
        4: '退回'
      }
      return sMap[status]
    },
    dateFormat(data) {
      if (data) {
        return moment(data).format('YYYY-MM-DD')
      } else {
        return ''
      }
    },
    confirm() {
      if (this.selectNode) {
        this.getCheckList(this.selectNode)
      } else {
        this.show = false
      }
    },
    // 根据id获取 项目清单列表
    getCheckList(obj) {
      this.$emit('getSelectedRows', obj)
      this.show = false
    },
    pageChange(data) {
      this.pageParams = data
      this.getDataList()
    },
    getSelectedRows(data) {

    },
    getDataList() {
      const params = {
        ...this.pageParams
      }
      getLaborContractFinishInfoList(params).then(res => {
        const { data, total } = res.data || {}
        if (data) {
          this.dataList = data
          this.total = total - 0
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.com-form-title{
  font-size: 14px;
  font-weight: bold;
  line-height: 35px;
  color: #409EFF;
  border-bottom: 1px solid #dedede;
  margin-bottom: 6px;
}
::v-deep .content-box{
  overflow: hidden;
}
</style>
